/**
 * 用操作数据的方式来实现数据持久化
 */

let mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/itcast',{ useNewUrlParser: true });
let Schema = mongoose.Schema;
// 直接导出模型构造函数
module.exports = mongoose.model('Student', new Schema({
  name: {
    type: String,
    required: true
  },
  gender: {
    type: Number,
    enum: [0, 1],
    default: 0
  },
  age: {
    type: Number,
    required: true
  },
  hobbies: {
    type: String
  }
}));
